<?php
namespace GrouppaGroup;
class MessageFromApp
{
    /**
     * to which group the message is intended
     * @var string
     */
    public $toGroup;
    /**
     * which task is supposed to be executre in controller
     * @var string
     */
    public $task;
    /**
     * serialized in JSON arguments of a task
     * @var string
     */
    public $serializedArguments;
    /**
     * user from which the message was sent
     * @var string
     */
    public $from;
    /**
     * id of the message
     * @var integer
     */
    public $id;
    /**
     * name of destination controller on the server
     * @var string
     */
    public $toController;

    /**
     * type of the message, used to identify response messages easily
     * @var string
     */
    public $messageType;

    /**
     * access token confirming that the user is logged in
     * in case that client possesses one
     * @var string
     */
    public $accessToken;
    /**
     * creates a new instance of MessageFromApp from the provided json object
     * @param  object         $jsonMessage json object decoded from a message
     * @return MessageFromApp a new instance
     */
    public static function createFromJSON($jsonMessage)
    {
        //CHECKED:  create a new instance of MessageFromApp from the provided json object
        $newMessage = new MessageFromApp();
        $newMessage->from = isset($jsonMessage->from) ? $jsonMessage->from : '';
        $newMessage->id = isset($jsonMessage->id) ? $jsonMessage->id : '';
        $newMessage->serializedArguments = isset($jsonMessage->serializedArguments) ? $jsonMessage->
            serializedArguments : '';
        $newMessage->task = isset($jsonMessage->task) ? $jsonMessage->task : '';
        $newMessage->toController = isset($jsonMessage->toController) ? $jsonMessage->
            toController : '';
        $newMessage->toGroup = isset($jsonMessage->toGroup) ? $jsonMessage->toGroup : '';
        $newMessage->messageType = isset($jsonMessage->messageType) ? $jsonMessage->
            messageType : '';
        $newMessage->accessToken = isset($jsonMessage->accessToken) ? $jsonMessage->
            accessToken : '';

        return $newMessage;
    }

}
